package com.decade.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ModelAndViewController {

    @GetMapping("doModelAndView")
    public String doModelAndView(Model model){
        model.addAttribute("name","张三");
        model.addAttribute("age",20);
        return "default";
    }

    @GetMapping("doModelAndView02")
    public ModelAndView doModelAndView(ModelAndView mv){
        mv.addObject("name","张三");
        mv.addObject("age",20);
        mv.setViewName("default");
        return mv;
    }//这里的modelandview是model对象和view的对象的一个合体

    @GetMapping("doModelAndView03")
    public ModelAndView doModelAndView03(ModelAndView mv){
        List<String> list = new ArrayList<>();
        list.add("上海");
        list.add("广州");
        list.add("深圳");
        mv.addObject("citys",list);
        mv.setViewName("default");
        return mv;
    }
}
